// ignore_for_file: constant_identifier_names, avoid_print



import 'package:airbnb_clone/internal/cache/app_cache.dart';
import 'package:airbnb_clone/models/response.dart';

import '../core/hi_net.dart';
import '../request/base_request.dart';
import '../request/login_request.dart';


/// 与服务端通信 , 数据交互和持久化的操作都放在 DAO 层:
class LoginDao {
  static const BOARDING_PASS = "token";

  static login(String userName, String password) {
    return _send(userName, password);
  }

  static Future<TiebaResponse> _send(String userName, String password) async {
    BaseRequest request;
    // 登录请求
    request = LoginRequest();
    // 为 request 添加参数:
    request
        .addJson("username", userName)
        .addJson("password", password)
        .addHeader("Content-Type", "application/json");

    var result = await HiNet.getInstance().fire(request);
    print("login_dao: $result");
    TiebaResponse response = TiebaResponse.fromMap(result);
    return response;
  }

  static String? getBoardingPass() {
    return AppCache.token;
  }
}
